package com.monitor.util.command;

import java.io.File;

public class CommandStrUtil {
	
	/**
	 * @param srcPath	如果是文件夹则复制文件夹全部信息，如果是文件，则复制文件
	 * @param distPATH  
	 * 			1、不存在：
	 * 			2、文件夹：
	 * 				创建文件夹
	 * 			3、存在且是文件：复制进上一级目录
	 * @return
	 */
	public static String getUnixCopyCmd(String srcPath, String distPATH){
		File src = new File(srcPath);
		if(!src.exists())return null;
		
		String cmdParam = "";
		if(src.isDirectory()){
			cmdParam = " -r ";
		}
		
		File dist = new File(distPATH);
		if( !dist.exists() ){
			dist.mkdirs();
		}else if( dist.isFile() ){
			dist = dist.getParentFile();
		}
		
		StringBuffer cmdBuff = new StringBuffer();
		cmdBuff.append("cp ").append(cmdParam).append(" ").append(src.getAbsolutePath()).append(" ").append(dist.getAbsolutePath());
		
		return cmdBuff.toString();
	}
	
	public static void main(String[] args){
		
		System.out.println(getUnixCopyCmd("/home/huanglj/document/","/home/huanglj/document/test"));
	}
}
